package com.navi168.fwq21.hyzl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.amap.mapapi.core.GeoPoint;
import com.amap.mapapi.poisearch.PoiTypeDef;
import com.navi168.fwq21.R;

import android.app.ExpandableListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ExpandableListView;
import android.widget.SimpleExpandableListAdapter;
import android.widget.TextView;

public class NearPoi extends ExpandableListActivity {
	private ExpandableListView expandableListView;
	private List<Map<String, Object>> parentList = new ArrayList<Map<String, Object>>();
	private List<List<Map<String, String>>> childList = new ArrayList<List<Map<String, String>>>();
	private String[] poi_typeStrings = { "餐饮", "休闲", "交通", "银行", "住宿", "生活",
			"购物", "汽车服务", "公共服务" };
	private GeoPoint point;
	private TextView whereTextView;
	private Bundle bundle;
	private Button searchButton;
	private EditText searchkey;
	private int lat;
	private int log;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.nearpoi);
		// expandableListView = (ExpandableListView)
		// findViewById(R.id.nearpoi_expandableList);
		bundle = this.getIntent().getExtras();
		whereTextView = (TextView) findViewById(R.id.wheretext);
		whereTextView.setText(bundle.getString("searchtype"));//获取的是在什么地方的poi搜索
		
		searchButton = (Button) findViewById(R.id.nearpoi_but);
		searchkey = (EditText) findViewById(R.id.nearpoi_key);
		searchButton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				bundle.putString("poitype", "");
				bundle.putString("poikey", searchkey.getText().toString());
				Intent intent1 = new Intent();
				intent1.putExtras(bundle);
				intent1.setClass(NearPoi.this, PoiList.class);
				startActivity(intent1);
				
				
			}
		});
		
		creatparent();
		creatchild();

		SimpleExpandableListAdapter adapter = new SimpleExpandableListAdapter(
				NearPoi.this, parentList, R.layout.expan_group,
				new String[] { "classname" }, new int[] { R.id.group_name },
				childList, R.layout.expan_chil, new String[] { "child" },
				new int[] { R.id.chil_name });
		setListAdapter(adapter);
	}


	/**
	 * 设置哪个二级目录被默认选中
	 */
	@Override
	public boolean setSelectedChild(int groupPosition, int childPosition,
			boolean shouldExpandGroup) {
		// do something
		return super.setSelectedChild(groupPosition, childPosition,
				shouldExpandGroup);
	}

	/**
	 * 设置哪个一级目录被默认选中
	 */
	@Override
	public void setSelectedGroup(int groupPosition) {
		// do something
		super.setSelectedGroup(groupPosition);
	}

	/**
	 * 当二级条目被点击时响应
	 */
	@Override
	public boolean onChildClick(ExpandableListView parent, View v,
			int groupPosition, int childPosition, long id) {
		String poitype = (String) parentList.get(groupPosition)
				.get("classname");
		String poikey = childList.get(groupPosition).get(childPosition)
				.get("child");
		poitype = getpoitype(poitype);
		
		bundle.putString("poitype", poitype);
		bundle.putString("poikey", poikey);
		

		Intent intent = new Intent(this, PoiList.class);
		intent.putExtras(bundle);
		startActivity(intent);
		Log.i("mylog", poitype + "--" + poikey);
		return super.onChildClick(parent, v, groupPosition, childPosition, id);
	}

	private String getpoitype(String classname) {
		if (classname.equals("餐饮")) {
			return "餐饮服务|";
		}
		if (classname.equals("休闲")) {
			return "体育休闲服务|生活服务|";
		}
		if (classname.equals("交通")) {
			return "交通设施服务|";
		}
		if (classname.equals("银行")) {
			return "金融保险服务|";
		}
		if (classname.equals("住宿")) {
			return "住宿服务|";
		}
		if (classname.equals("生活")) {
			return "生活服务|公共设施|";
		}
		if (classname.equals("购物")) {
			return "购物服务|";
		}
		if (classname.equals("汽车服务")) {
			return "汽车服务|汽车销售|汽车维修|摩托车服务|道路附属设施|";
		}
		if (classname.equals("公共服务")) {
			return "公共设施|";
		}
		return null;
	}

	private void creatparent() {
		for (int i = 0; i < poi_typeStrings.length; i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("classname", poi_typeStrings[i]);
			parentList.add(map);
		}

	}

	private void creatchild() {
		Map<String, String> map;
		List<Map<String, String>> child1 = new ArrayList<Map<String, String>>();
		String[] child_name = getResources().getStringArray(R.array.canying);
		for (int i = 0; i < child_name.length; i++) {
			map = new HashMap<String, String>();
			map.put("child", child_name[i]);
			child1.add(map);
		}
		childList.add(child1);

		List<Map<String, String>> child2 = new ArrayList<Map<String, String>>();
		child_name = getResources().getStringArray(R.array.xiuxian);
		for (int i = 0; i < child_name.length; i++) {
			map = new HashMap<String, String>();
			map.put("child", child_name[i]);
			child2.add(map);
		}
		childList.add(child2);

		List<Map<String, String>> child3 = new ArrayList<Map<String, String>>();
		child_name = getResources().getStringArray(R.array.jiaotong);
		for (int i = 0; i < child_name.length; i++) {
			map = new HashMap<String, String>();
			map.put("child", child_name[i]);
			child3.add(map);
		}
		childList.add(child3);

		List<Map<String, String>> child4 = new ArrayList<Map<String, String>>();
		child_name = getResources().getStringArray(R.array.yinghang);
		for (int i = 0; i < child_name.length; i++) {
			map = new HashMap<String, String>();
			map.put("child", child_name[i]);
			child4.add(map);
		}
		childList.add(child4);

		List<Map<String, String>> child5 = new ArrayList<Map<String, String>>();
		child_name = getResources().getStringArray(R.array.zhusu);
		for (int i = 0; i < child_name.length; i++) {
			map = new HashMap<String, String>();
			map.put("child", child_name[i]);
			child5.add(map);
		}
		childList.add(child5);
		List<Map<String, String>> child6 = new ArrayList<Map<String, String>>();
		child_name = getResources().getStringArray(R.array.shenghuo);
		for (int i = 0; i < child_name.length; i++) {
			map = new HashMap<String, String>();
			map.put("child", child_name[i]);
			child6.add(map);
		}
		childList.add(child6);
		List<Map<String, String>> child7 = new ArrayList<Map<String, String>>();
		child_name = getResources().getStringArray(R.array.gouwu);
		for (int i = 0; i < child_name.length; i++) {
			map = new HashMap<String, String>();
			map.put("child", child_name[i]);
			child7.add(map);
		}
		childList.add(child7);
		List<Map<String, String>> child8 = new ArrayList<Map<String, String>>();
		child_name = getResources().getStringArray(R.array.qichi);
		for (int i = 0; i < child_name.length; i++) {
			map = new HashMap<String, String>();
			map.put("child", child_name[i]);
			child8.add(map);
		}
		childList.add(child8);
		List<Map<String, String>> child9 = new ArrayList<Map<String, String>>();
		child_name = getResources().getStringArray(R.array.gonggong);
		for (int i = 0; i < child_name.length; i++) {
			map = new HashMap<String, String>();
			map.put("child", child_name[i]);
			child9.add(map);
		}
		childList.add(child9);

	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

}
